package top.wshape1.shiziapi.search.controller;

import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import top.wshape1.shiziapi.common.domain.ProjectSearch;
import top.wshape1.shiziapi.common.utils.R;
import top.wshape1.shiziapi.search.domain.ProjectSearchPage;
import top.wshape1.shiziapi.search.service.ProjectSearchService;

import java.io.IOException;
import java.util.List;

/**
 * @author Wshape1
 * @version 1.0
 * @description SearchController
 * @since 2023-11-20
 */


@RestController
@RequestMapping("/search")
public class SearchController {

    @Resource
    private ProjectSearchService projectSearchService;

    /**
     * 热门项目
     *
     * @param page
     * @return
     * @throws IOException
     */
    @PostMapping("/hot")
    public R<ProjectSearchPage> hot(@RequestParam(value = "page", required = false, defaultValue = "1") Integer page) throws IOException {

        ProjectSearchPage projectSearchList = projectSearchService.getHotProjects(page);

        return R.ok(projectSearchList);
    }

    /**
     * 搜索项目
     *
     * @param page
     * @param keyword
     * @return
     * @throws IOException
     */
    @PostMapping()
    public R<ProjectSearchPage> search(@RequestParam(value = "page", required = false, defaultValue = "1") Integer page
            , @RequestParam(value = "keyword", required = false) String keyword) throws IOException {

        ProjectSearchPage projectSearchList = projectSearchService.searchProject(page, keyword);

        return R.ok(projectSearchList);
    }



}
